package cn.huanzi.qch.baseadmin.diy_enterty;


import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.validator.constraints.Range;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Data
@Entity //标记类为数据库实体类
@Table(name = "blog", catalog = "test2", schema = "xx表",
        indexes = {@Index(columnList = "gender"),
                @Index(columnList = "name")})
public class Blog implements Serializable {
    /*
        @Id：指定主键
        @GeneratedValue：
        指定主键生成策略
        不设置参数则按照默认的策略-AUTO，那么在数据库中会多生成一张表用于记录各个表的主键
    */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY) //代表主键是自增 默认为AUTO
    @Column(name = "id", columnDefinition = "bigint(20) COMMENT '主键'")
    private Long id;
    @Column(name = "code", unique = true, nullable = false, length = 20, columnDefinition = "varchar(100) COMMENT '编码'")
    private String code;
    @Column(name = "name", columnDefinition = "varchar(100) COMMENT '名字'")
    private String name;
    @Column(name = "gender", columnDefinition = "int(1) default 0 comment '性别 '")
    private Integer gender;

    @Range(min = 0, max = 2)
    @Column(name = "enable", nullable = false, columnDefinition = "int(1) default 0 comment '启用状态：0：启用，1：禁用，2：已删除'")
    private Integer enable;

    @Lob
    @Basic(fetch = FetchType.LAZY) //大文件懒加载
    @Column(name = "content", columnDefinition = "text comment '扩展角色'")
    private String content;


    @Transient //表示忽略生成变量到数据库
    private Integer views; //浏览次数

    @CreationTimestamp
    @Column(name = "create_time", columnDefinition = "DATETIME COMMENT '添加时间'") //
//    @Temporal(TemporalType.TIMESTAMP) //Java系统生成时间 转换为 数据库时间类型
    private Date createTime;

    @Column(name = "update_time", columnDefinition = "DATETIME COMMENT '更新时间'") //不能去掉DATETIME
    @UpdateTimestamp //更新时自动更新时间
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;

    @Version
    @Column(name = "version", columnDefinition = "bigint COMMENT '版本号'")
    private long version;

//    //实体类关系：多个blog对应一个type,多的一方是维护端
//    @ManyToOne
//    private Type type;


}